<template>
	<view class="content_box">
		<view>
			<ul class="user_info">
				<li><label class="left">姓名</label><span class="right">{{data.xming0}}</span></li>
				<li><label class="left">性别</label><span class="right">{{data.xbie00}}</span></li>
				<li><label class="left">证件类型</label><span class="right">身份证</span></li>
				<li><label class="left">证件号码</label><span class="right">{{data.sfzh00}}</span></li>
			</ul>
			<ul class="pay_info">
				<li><label  class="left">预交金总额</label><span class="right">{{data.yjjze0}}</span></li>
				<li><label  class="left">住院预交金余额</label><span class="right">{{data.fyye}}</span></li>
				<li><label  class="left">住院总费用</label><span class="right">{{data.zyzfy0}}</span></li>
			</ul>
		</view>
		<view class="pay_box">
			<b>充值(元)</b>
			<input type="digit" v-model="payMoney" placeholder="请输入充值额度" class="ipt" />
		</view>
		<view>
			<button class="btn" @click="nowPay()">立即充值</button>
		</view>
	</view>
</template>

<script>
	import pay from "@/tool/pay.js"
	export default {
		data() {
			return {
				data:{},
				payMoney:"",
			}
		},
		onLoad(option) {
			if(option.user){
				this.init(JSON.parse(option.user));
			}
		},
		methods: {
			init(user){
				if(user){
					this.data=user;
				}else{
					
				}
				
			},
			nowPay(){
				if(this.payMoney==""){
					return;
				}
				let out_trade_no="WXPREPAY"+new Date().getTime();
				var payJson={
					"out_trade_no": out_trade_no,//后台生成，唯一性
					"description": "住院预交金充值",
					"notify_url": "http://127.0.0.1",//异步回调地址，后台配置
					"amount": {
						"total": (parseFloat(this.payMoney) *100),//(parseFloat(this.params.ghzlf0) *100),//parseFloat(this.params.ghzlf0) *100
						"currency": "CNY"
					},
					"payer": {
						"openid": uni.getStorageSync("openid")
					}
				};
				payJson.user=this.data;
				
				pay.prePay(payJson,success=>{
					let user=this.data;
					let date=new Date();
					let yyyy=date.getFullYear();
					let MM=date.getMonth();
					if(MM<10){
						MM="0"+MM;
					}
					let dd=date.getDate();
					if(dd){
						dd="0"+dd;
					}
					let params={
						zyh000:user.zyh000,
						kh0000:user.sfzh00,
						klx000:"3",
						patid0:user.patid0,
						xming0:user.xming0,
						czlx00:"2",
						czje00:this.payMoney,
						yhjyxx:{
							"jylx00":"3",
							"zffs00": "2",
							"jysj00": (yyyy+"-"+MM+"-"+dd),
							"yhkh00": "",
							"jyddh0": out_trade_no,
							"jyje00": this.payMoney,
							"bz0000": "住院预交金充值",
						},
						ddh000:out_trade_no,
						zffs00:"2",
						ywlsh0:""+new Date().getTime(),
						"funid":"F07.05.02.01"
					};
					this.$postJson("/qnyesb/qnyesbproxy",params,res=>{
						if(res.state==0){
							uni.showToast({
								title:"支付成功",
								icon:"success",
								duration:3000
							})
						}else{
							uni.showToast({
								title:res.message,
								icon:"error",
								duration:3000
							})
						}
					})
				},error=>{
					//取消支付，支付失败等等 取消或更新失败状态
					uni.showToast({
						title:"支付失败",
						icon:"error"
					})
				})
				
			},
			pays(item){
				console.log(item);
				let out_trade_no="WXPREPAY"+new Date().getTime();
				let user=item;
				let date=new Date();
				let yyyy=date.getFullYear();
				let MM=date.getMonth()+1;
				if(MM<10){
					MM="0"+MM;
				}
				let dd=date.getDate();
				if(dd<10){
					dd="0"+dd;
				}
				let HH=date.getHours();
				if(HH<10){
					HH="0"+HH;
				}
				let mm=date.getMinutes();
				if(mm<10){
					mm="0"+mm;
				}
				let ss=date.getSeconds();
				if(ss<10){
					ss="0"+ss;
				}
				
				let params={
					zyh000:this.data.zyh000,
					kh0000:user.sfzh00,
					klx000:"3",
					patid0:user.patid0,
					xming0:user.xming0,
					czlx00:"2",
					czje00:"0.01",
					yhjyxx:JSON.stringify({
						"jylx00":"3",
						"zffs00": "2",
						"jysj00": (yyyy+"-"+MM+"-"+dd),
						"yhkh00": "",
						"jyddh0": out_trade_no,
						"jyje00": "0.01",
						"bz0000": "住院预交金充值",
					}),
					zffs00:"2",
					ddh000:out_trade_no,
					jsddh0:out_trade_no+"2222",
					ywlsh0:""+new Date().getTime(),
					funid:"F07.05.02.01",
					funid0:"3"
				};
				this.$postJson("/qnyesb/qnyesbproxy",params,res=>{
					if(res.state==0){
						uni.showToast({
							title:"支付成功",
							icon:"success",
							duration:3000
						})
					}else{
						uni.showToast({
							title:res.message,
							icon:"error",
							duration:3000
						})
					}
				})
				return;
				
				
				let myPrePayData={
					"kh0000":user.kh0000,
					"klx000":"3",
					"xming0":user.xming0,
					"mzh000":"21101279",
					"zffs00":"2",
					"jyrq00":yyyy+"-"+MM+"-"+dd+" "+HH+":"+mm+":"+ss,//就诊日期
					"ddh000":out_trade_no,
					"ddje00":"0.01",
					"ddlx00":"1",
					"xtmc00":"3",
					"sfzh00":user.kh0000,
					"patid0":user.patid0,
					"hdurl0":"",
					"funid":"F07.15.02.01"
				};
				this.$postJson("/qnyesb/qnyesbproxy",myPrePayData,res=>{
					console.log(this.data);
					
				})
			}
		}
	}
</script>

<style>
.content_box .user_info,.pay_info,.pay_box{
	width: 92%;
	margin: 0 auto;
	background-color: #FFFFFF;
	margin-top: 10px;
	padding: 10px;
	border-radius: 4px;
}
.content_box ul li{
	display: flow-root;
	padding: 10px;
}
.content_box ul li label{
	color: #999999;
}
.content_box .pay_info li{
	border-bottom: 1px solid #F5F5F5;
}
.content_box .pay_box{
	padding-bottom: 50px;
}
.content_box .pay_box .ipt{
	height: 40px;
	border: 1px solid #CCCCCC;
	opacity: 1;
	border-radius: 20px;
	text-indent: 1em;
	margin-top: 20px;
}
.btn{
	height: 46px;
	background: rgba(54, 146, 255,1);
	opacity: 1;
	border-radius: 28px;
	color: #FFFFFF;
	margin-top: 30px;
}
</style>
